﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entity;
using BLL;
using BLL.Access;
using System.Data;
using Platform.Http;
using Web.Class;
using System.IO;
using System.Data.Odbc;
using System.Data.OleDb;
using DevExpress.Web;

namespace Web.Pages.QuShui.DiXiaS._8.QiTaGL
{
    public partial class CaiGuanJZXD : BasePage
    {
        #region 属性
        
        #endregion

        #region 变量
        SpHelper sphelper = new SpHelper();
        #endregion

        #region 方法

        private void BindData()
        {

            DataSet ds = sphelper.P_QS_QT_CAIHUANZXD(txtYear.Text,txtRQ.Text, txtDYRQ.Text);
            gvList.DataSource = ds;
            gvList.DataBind(); 
        }
        private void InitControl()
        {
            txtDYRQ.Text = DateTime.Now.AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd");
            txtRQ.Text = DateTime.Now.ToString("yyyy-MM-dd");
            txtRQ.CalendarProperties.ClearButtonText = "清除";
            txtRQ.CalendarProperties.TodayButtonText = "今天";
            txtDYRQ.CalendarProperties.TodayButtonText = "今天";
            txtDYRQ.CalendarProperties.ClearButtonText = "清除";
            this.ScriptManager1.RegisterPostBackControl(this.btnExcel);
        }
        #endregion

        #region 事件
        
        protected void Page_Load(object sender, EventArgs e)
        {
            InitControl();
        }
        protected void btnBindRight_Click(object sender, EventArgs e)
        {
            BindData();
        }
        protected void btnQuanXuan_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < gvList.VisibleRowCount; i++)
            {
                ASPxCheckBox cb = (ASPxCheckBox)gvList.FindRowCellTemplateControl(i, (GridViewDataColumn)gvList.Columns[0], "cid");
                cb.Checked = true;
            }
        }
        protected void btnFanXuan_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < gvList.VisibleRowCount; i++)
            {
                ASPxCheckBox cb = (ASPxCheckBox)gvList.FindRowCellTemplateControl(i, (GridViewDataColumn)gvList.Columns[0], "cid");
                cb.Checked = false;
            }
        }
        protected void btnExcel_Click(object sender, EventArgs e)
        {
            if (gvList.VisibleRowCount > 0)
            {
                DataTable alldt = new DataTable();
                alldt.Columns.Add("用户号");
                alldt.Columns.Add("用户名");
                alldt.Columns.Add("年");
                alldt.Columns.Add("返回日期");
                alldt.Columns.Add("打印日期");
                alldt.Columns.Add("邮政编码");
                alldt.Columns.Add("用户地址");
               
                for (int i = 0; i < gvList.VisibleRowCount; i++)
                {
                    HiddenField yonghuh = (HiddenField)gvList.FindRowCellTemplateControl(i, (GridViewDataColumn)gvList.Columns[0], "hid");
                    HiddenField yonghum = (HiddenField)gvList.FindRowCellTemplateControl(i, (GridViewDataColumn)gvList.Columns[0], "S_YONGHUM");
                    HiddenField dizhi = (HiddenField)gvList.FindRowCellTemplateControl(i, (GridViewDataColumn)gvList.Columns[0], "S_DIZHI");
                    HiddenField youbian = (HiddenField)gvList.FindRowCellTemplateControl(i, (GridViewDataColumn)gvList.Columns[0], "S_YOUBIAN");

                    HiddenField nian = (HiddenField)gvList.FindRowCellTemplateControl(i, (GridViewDataColumn)gvList.Columns[0], "I_Y");
                    HiddenField fanhuirq = (HiddenField)gvList.FindRowCellTemplateControl(i, (GridViewDataColumn)gvList.Columns[0], "FANHUIRQ");
                    HiddenField dayinrq = (HiddenField)gvList.FindRowCellTemplateControl(i, (GridViewDataColumn)gvList.Columns[0], "DAYINRQ");


                    ASPxCheckBox cb = (ASPxCheckBox)gvList.FindRowCellTemplateControl(i, (GridViewDataColumn)gvList.Columns[0], "cid");
                    if (cb.Checked)
                    {
                        DataRow newdr = alldt.NewRow();
                        newdr["用户号"] = yonghuh.Value;
                        newdr["用户名"] = yonghum.Value;
                        newdr["用户地址"] = dizhi.Value;
                        newdr["邮政编码"] = youbian.Value;

                        newdr["年"] = nian.Value;
                        newdr["返回日期"] = fanhuirq.Value;
                        newdr["打印日期"] = dayinrq.Value;
                        alldt.Rows.Add(newdr);
                    }
                }

                PageTools.CreateExcel(alldt,this.txtYear.Text+"年采灌井征询单用户表.xls");
            }
        }
       
        /// <summary>
        /// 打印
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnDaYin_Click(object sender, EventArgs e)
        {

        }
        #endregion

       

        
    }
}